package excollection;

import java.util.ArrayList;

/**
 * @author: knowno
 * @create: 2025-09-15 11:02
 * @Version 1.0
 **/
public class TestArrayList {
    public static void main(String[] args) {

        //创建一个ArrayList集合
        ArrayList arrayList1 = new ArrayList();

        //添加元素
        arrayList1.add("hello");
        arrayList1.add("world");
        arrayList1.add("java");

        //打印集合
        System.out.println(arrayList1);

        //获取元素
        System.out.println(arrayList1.get(0));

        //删除元素
        arrayList1.remove(0);
        System.out.println(arrayList1);

        //集合的大小
        System.out.println(arrayList1.size());

        //遍历集合
        for (int i = 0; i < arrayList1.size(); i++) {
            System.out.println(arrayList1.get(i));
        }

        //增强for循环遍历集合
        for (Object o : arrayList1) {
            System.out.println(o);
        }

        //集合的清空
        arrayList1.clear();
        System.out.println(arrayList1);

        //判断集合是否为空
        System.out.println(arrayList1.isEmpty());

        //判断集合是否包含某个元素
        System.out.println(arrayList1.contains("hello"));



    }
}
